package com.jh.maven.hw;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class fram extends JFrame {

    /*
     * 界面设计
     * */
    public fram(){
        Container c = getContentPane(); //定义一个顶级容器c
        JPanel jp = new JPanel();   //新建JPanel面板--jp
        JButton button1 = new JButton("新建联系人");
        JButton button2 = new JButton("删除联系人");
        JButton button3 = new JButton("修改联系人");
        JButton button4 = new JButton("查找联系人");
        JButton button5 = new JButton("显示联系人");  
        jp.setLayout(new GridLayout(1,5,5,5));//新建网格布局管理器
        jp.add(button1);
        jp.add(button2);
        jp.add(button3);
        jp.add(button4);
        jp.add(button5);
        c.add(jp);//将JPanel面板jp添加到顶级容器c中
        setSize(700,400);
        setTitle("*通 讯 录 管 理 系 统*");
        setVisible(true);
        setResizable(true);//窗体大小不可改变
        setLocationRelativeTo(null);//居中显示
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        /*
         *按键响应
         * 
         * */
        button1.addActionListener(new ActionListener(){//新建功能实现
            public void actionPerformed(ActionEvent arg0){
                try {
					Infro.addFunction();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });
        button2.addActionListener(new ActionListener(){//删除功能实现
            public void actionPerformed(ActionEvent arg0){
                Infro.deleteFunction();
            }
        });
        button3.addActionListener(new ActionListener(){//修改功能实现
            public void actionPerformed(ActionEvent arg0){
                try {
					Infro.reditFunction();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        });
        button4.addActionListener(new ActionListener(){//查询功能实现
            public void actionPerformed(ActionEvent arg0){
                try {
                    Infro.searchFunction();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        button5.addActionListener(new ActionListener(){//显示功能实现
            public void actionPerformed(ActionEvent arg0){
                try {
                    Infro.showFunction();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }
    public static void main(String[] args){
    	try {
			Infro.readFunction();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
         new fram();
        Infro a = new Infro("", "", "", "", "");
    }
}